//
//  StoreInfoView.m
//  phmall
//
//  Created by admin on 2017/9/17.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "StoreInfoView.h"

@interface StoreInfoView ()
//店铺等级
@property(nonatomic,assign)ShopLevelIcon icon;
@property(nonatomic,strong)UILabel *phone;
@end


@implementation StoreInfoView

-(instancetype)init{
    if (self=[super init]) {
        self.backgroundColor=[UIColor whiteColor];
        self.storeImg=[[UIImageView alloc] init];
//        self.storeImg.image=[UIImage imageNamed:@"图片"];
        [self addSubview:self.storeImg];
       
        
        self.credit=[[UILabel alloc] init];
        self.credit.text=[NSString stringWithFormat:@"%@:",Localized(@"信用")];
        self.credit.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.credit.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.credit];
       
        self.storeName=[[UILabel alloc] init];
//        self.storeName.text=@"Look Fantastiz";
        [self addSubview:self.storeName];
        self.storeName.font=[UIFont systemFontOfSize:15];
        self.storeName.textColor=[UIColor colorWithHexString:@"#121212"];
        
        self.describe=[[UILabel alloc]init];
        self.describe.text=Localized(@"描述");
        self.describe.textAlignment=NSTextAlignmentCenter;
        self.describe.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.describe.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.describe];
        
        self.serve=[[UILabel alloc]init];
        self.serve.text=Localized(@"服务");
        self.serve.textAlignment=NSTextAlignmentCenter;
        self.serve.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.serve.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.serve];
        
        self.express=[[UILabel alloc]init];
        self.express.text=Localized(@"快递");
        self.express.textAlignment=NSTextAlignmentCenter;
        self.express.textColor=[UIColor colorWithHexString:@"#adadad"];
        self.express.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.express];
        
        self.describeNum=[[UILabel alloc]init];
        self.describeNum.text=@"4.8↑";
        self.describeNum.textAlignment=NSTextAlignmentCenter;
        self.describeNum.textColor=[UIColor orangeColor];
        self.describeNum.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.describeNum];
        
        self.serveNum=[[UILabel alloc]init];
        self.serveNum.text=@"4.8↑";
        self.serveNum.textAlignment=NSTextAlignmentCenter;
        self.serveNum.textColor=[UIColor orangeColor];
        self.serveNum.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.serveNum];
        
        self.expressNum=[[UILabel alloc]init];
        self.expressNum.text=@"4.8↑";
        self.expressNum.textAlignment=NSTextAlignmentCenter;
        self.expressNum.textColor=[UIColor orangeColor];
        self.expressNum.font=[UIFont systemFontOfSize:13];
        [self addSubview:self.expressNum];
        
        NSMutableDictionary *levelDict=[PublicClass countLevel:2333];
        int num=[levelDict[@"num"] intValue];
        ShopLevelIcon icon=(ShopLevelIcon)[levelDict[@"icon"] intValue];
        for (int i=0; i<num; i++) {
            UIImageView *creditImg=[[UIImageView alloc] init];
            switch (icon) {
                case 0:
                    creditImg.image=[UIImage imageNamed:@"灰星"];
                    break;
                    
                case 1:
                    creditImg.image=[UIImage imageNamed:@"红星"];
                    break;
                    
                case 2:
                    creditImg.image=[UIImage imageNamed:@"钻"];
                    break;
                    
                case 3:
                    creditImg.image=[UIImage imageNamed:@"银冠"];
                    break;
                    
                case 4:
                    creditImg.image=[UIImage imageNamed:@"金冠"];
                    break;
                default:
                    break;
            }
            [self addSubview:creditImg];
            [creditImg mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.credit);
                make.left.equalTo(self.credit.mas_right).with.offset(8+i*18);
                make.width.height.mas_offset(16);
            }];
        }
        


        self.line=[[UIView alloc] init];
        self.line.backgroundColor=[UIColor colorWithHexString:@"#efeff4"];
        [self addSubview:self.line];
        
        self.line2=[[UIView alloc] init];
        self.line2.backgroundColor=[UIColor colorWithHexString:@"#efeff4"];
        [self addSubview:self.line2];
        
        self.enterLine=[[UIView alloc] init];
        [self addSubview:self.enterLine];
        self.enterLine.backgroundColor=[UIColor groupTableViewBackgroundColor];
        
        self.enter=[UIButton buttonWithType:UIButtonTypeCustom];
        self.enter.titleLabel.font=[UIFont systemFontOfSize:16];
        [self.enter setImage:[UIImage imageNamed:@"图标"] forState:UIControlStateNormal];
        [self.enter setTitle:Localized(@"进入店铺") forState:UIControlStateNormal];
        [self.enter addTarget:self action:@selector(goToShop) forControlEvents:UIControlEventTouchUpInside];
        [self.enter setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [self addSubview:self.enter];
        
//        self.collect=[UIButton buttonWithType:UIButtonTypeCustom];
//        self.collect.titleLabel.font=[UIFont systemFontOfSize:15];
//        ViewBorderRadius(self.collect, 3, 1, [UIColor orangeColor]);
//        [self.collect setTitle:@"收藏店铺" forState:UIControlStateNormal];
//        [self.collect setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
//        [self addSubview:self.collect];
        
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    
    [self.storeImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).with.offset(5);
        make.left.equalTo(self).with.offset(10);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(70);
    }];
    
    
    [self.credit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.storeImg).with.offset(-10);
        make.left.equalTo(self.storeImg.mas_right).with.offset(10);
    }];
    
    [self.storeName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.storeImg).offset(10);
        make.left.equalTo(self.credit);
    }];
 
    [self.describe mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.width.offset(SCREEN_WIDTH/3);
        make.top.equalTo(self.storeImg.mas_bottom).offset(20);
    }];
    
    [self.serve mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.describe.mas_right).offset(0);
        make.width.offset(SCREEN_WIDTH/3);
        make.top.equalTo(self.storeImg.mas_bottom).offset(20);
    }];
    
    [self.express mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.serve.mas_right).offset(0);
        make.width.offset(SCREEN_WIDTH/3);
        make.top.equalTo(self.storeImg.mas_bottom).offset(20);
    }];
    
    [self.describeNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.width.offset(SCREEN_WIDTH/3);
        make.top.equalTo(self.express.mas_bottom).offset(5);
    }];
    
    [self.serveNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.describe.mas_right).offset(0);
        make.width.offset(SCREEN_WIDTH/3);
        make.top.equalTo(self.serve.mas_bottom).offset(5);
    }];
    
    [self.expressNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.serve.mas_right).offset(0);
        make.width.offset(SCREEN_WIDTH/3);
        make.top.equalTo(self.serve.mas_bottom).offset(5);
    }];

    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(1);
        make.centerX.equalTo(self.describe.mas_right);
        make.top.equalTo(self.describe);
        make.bottom.equalTo(self.describeNum);
    }];
    
    [self.line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(1);
        make.centerX.equalTo(self.serve.mas_right);
        make.top.equalTo(self.describe);
        make.bottom.equalTo(self.describeNum);
    }];
    
    [self.enterLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).with.offset(15).priorityHigh();
        make.right.equalTo(self.mas_right).with.offset(-15).priorityHigh();
        make.height.offset(1);
        make.top.equalTo(self.expressNum.mas_bottom).with.offset(10);
        //        make.bottom.equalTo(self.mas_bottom);
    }];
    
    [self.enter mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.enterLine.mas_bottom).with.offset(10);
//        make.height.offset(25);
//        make.width.offset(80);
        make.centerX.equalTo(self).offset(0);
    }];
    [self.enter layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleLeft imageTitleSpace:5];
//
//    [self.collect mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.expressNum.mas_bottom).with.offset(10);
//        make.height.offset(25);
//        make.width.offset(80);
//        make.centerX.equalTo(self).offset(80);
//    }];
    
}
-(void)goToShop{
    if (self.delegate && [self.delegate respondsToSelector:@selector(goToShop)]) {
        [self.delegate goToShop];
    }
}
-(void)setModel:(DetailsModel *)model{
    _model=model;
    self.storeName.text=model.shop_list[@"shop_name"];
    [self.storeImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@union/%@",IMGURL,model.shop_list[@"up_logo"]]] placeholderImage:[UIImage imageNamed:@"图片空白页(小图)"]];
}
@end
